package metier;

import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;

/**
 * Created with IntelliJ IDEA.
 * User: keita
 * Date: 12/06/13
 * Time: 23:58
 * To change this template use File | Settings | File Templates.
 */
public class Algo implements Runnable {
    private boolean initialized;
    Object o ;
    static HashMap<Integer,instrumentValue > tickTab;

    public Algo(Object o) {
        this.o = o;
        tickTab = new HashMap<Integer, instrumentValue>(20);
        this.initialized = false;
    }
    public HashMap<Integer, instrumentValue> getTickTab() {
        return tickTab;
    }





    private void updateTickPrice(tickPrice o) {
//        System.out.println(o);
//        System.out.println(tickTab.get(o.getTickerId()).name);


    }
    synchronized public void updateContract(contractInfo o) {
        System.out.print("Algo.updateContract ajout ID: ");
        System.out.print(o.getReqId());
        System.out.print(" Nom:");
        System.out.println(o.contractDetails.m_marketName);
        tickTab.put(new Integer(o.getReqId()), new instrumentValue(o.contractDetails.m_longName)) ;
        for (Integer mapKey : tickTab.keySet()) {
            System.out.println(tickTab.get(mapKey).name);
            // utilise ici  pour accéder aux valeurs
        }

    }




    @Override
    public void run() {
        if(o instanceof contractInfo  ) {
            contractInfo info = (contractInfo) o;
            updateContract(info);
        }
        if(o instanceof tickPrice  ) {
            tickPrice info = (tickPrice) o;
            updateTickPrice(info) ;
        }

    }
}
